在Android Studio 2.3.3中添加字体 | 您所在的位置:网站首页 › android studio 默认字体 › 在Android Studio 2.3.3中添加字体 |
问题描述
正如标题所说,我需要使用新字体.我目前使用 Android Studio 2.3.3. 我有一个文件 .ttf(字体文件),我想在 res 目录 (/res/font) 中添加这个字体. 我看到了其他问题,但似乎情况有所不同,因为很多人使用 Android Studio 3.0. 那么,对于我们这些穷人来说,正确的流程是什么? 解决方案1.在assets目录下新建fonts目录,将your.ttf字体文件放在这里 2.你可以改成这个. TextView tv = (TextView) findViewById(R.id.tv); Typeface tf = Typeface.createFromAsset(v.getContext().getAssets(), "fonts/your.ttf"); tv.setTypeface(tf);编辑 您也可以在 xml 代码中使用 android:typeface="sans" 、android:typeface="serif" 、android:typeface="monospace" . 在xml代码中使用android:fontFamily 从 android 4.1/4.2/5.0 开始,以下 Roboto字体系列可用: android:fontFamily="sans-serif" // roboto regular android:fontFamily="sans-serif-light" // roboto light android:fontFamily="sans-serif-condensed" // roboto condensed android:fontFamily="sans-serif-black" // roboto black android:fontFamily="sans-serif-thin" // roboto thin (android 4.2) android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)也用在样式中 字体.xml sans-serif-light sans-serif-medium sans-serif sans-serif-condensed sans-serif-black sans-serif-thin本文地址:https://www.itbaoku.cn/post/769303.html?view=all |
CopyRight 2018-2019 实验室设备网 版权所有 |